
$(function () {
    require([],function () {

        var $pwd = $(".pwd");
        var $tel = $(".tel");
        $(".btn").on("click",function () {
           
            var pwd = $pwd.val().trim();
            var tel = $tel.val().trim();
            var myreg = /^[1]{1}[345789]{1}[0-9]{9}$/;
            if(!myreg.test(tel)){
                window.wxc.xcConfirm("请输入正确的手机号", window.wxc.xcConfirm.typeEnum.error); 
            }else if(pwd.length < 6){
                window.wxc.xcConfirm("密码长度不能小于6", window.wxc.xcConfirm.typeEnum.error);
            }else{
                $.ajax({
                    url:'api/web/user/login',
                    type:"post",
                    data:{
                        tel:tel,
                        password:pwd
                    },
                    success:function (res) {
                        console.log(res);
                        var obj = getParams(window.location.href);
                        if(obj.url){
                            window.location.href = decodeURIComponent(obj.url);
                        }else{
                            window.location.href = '/';
                        }
                    }
                });
            }

        });
        
        $("#toregister").click(function () {
            var obj = getParams(window.location.href);
            if(obj.url){
                window.location.href = "/register?url=" + obj.url
            }else{
                window.location.href = '/register';
            }
        })



    })
});